<%@ page import="java.util.List" %>
<%@ page import="database.*" %>
<%@ page import="database.Class" %>
<%@ page import="utils.StringUtils" %><%--
  Created by IntelliJ IDEA.
  User: jimmyhsu
  Date: 2016/12/7
  Time: 14:19
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>学分管理</title>
    <link rel="stylesheet" href="../../static/js/jquery.min.js"/>
    <link rel="stylesheet" href="../../static/style/weui.css"/>
    <link rel="stylesheet" href="../../static/example/example.css"/>
    <link rel="stylesheet" href="../../static/style/myStyle.css"/>
    <link rel="stylesheet" href="../../static/css/bootstrap.css"/>
    <%
        int classId = -1;
        if (!StringUtils.isEmpty(request.getParameter("classId"))) {
            classId = Integer.parseInt(request.getParameter("classId"));
        }
        List<Class> classes = ClassDb.selectAllClasses();
        List<Credit> userCredits;
        if (classId < 0) {
            userCredits = CreditDb.selectAllUserCredits();
        } else {
            userCredits = CreditDb.selectUserCreditsByClassId(classId);
        }

    %>

</head>
<body style="background: transparent;color: #FFFFFF;">
<%@include file="Do/checkAdminLogin.jsp"%>
<br><br><br>
<h1 class = "page_title">学分</h1>
<button type="button" class="btn btn-primary" onclick="changeClass(-1)">全部</button>

<%
	for (Class aClass : classes) {
	    if (classId >= 0 &&aClass.getId() == classId) {
%>
    <button type="button" class="btn btn-primary" style="background-color: #105141;" onclick="changeClass(<%=aClass.getId()%>)"><%=aClass.getName()%></button>
<%
	    } else {
%>
 <button type="button" class="btn btn-primary" onclick="changeClass(<%=aClass.getId()%>)"><%=aClass.getName()%></button>
<%
        }
    }
%>
<table class = "zebra">
    <thead>
    <tr>
        <th>学号</th>
        <th>姓名</th>
        <th>已完成学分</th>
    </tr>
    </thead>
    <%
    for (Credit credit : userCredits){
        User user = UserDb.selectUserById(credit.getUserId());
    %>
    <tr>
        <td><%=user.getId()%></td>
        <td><%=user.getName()%></td>
        <td><%=credit.getCredit()%></td>
    </tr>
    <%
    }%>
</table>
<br>
<div style="text-align: center;">
<button class="greyBtn" style = "position: relative;" type = "button" onclick="onTable('<%=classId%>')">导出表格...</button>
</div>
<a href="#" id="toTop" style="display: block;-ms-transform:rotate(180deg); /* IE 9 */
    -moz-transform:rotate(180deg); /* Firefox */
    -webkit-transform:rotate(180deg); /* Safari and Chrome */
    -o-transform:rotate(180deg); /* Opera */"> <span id="toTopHover" style="opacity: 1;"> </span></a>

</body>
<script>
    function onTable(classId){
        location.href='Do/creditTable.jsp?classId='+classId;
    }
</script>
<script type="text/javascript">
    $(document).ready(function() {
        $().UItoTop({ easingType: 'easeOutQuart' });
    });
    function changeClass(classId) {
        location.href='credit.jsp?classId='+classId;
    }
</script>
<script type="text/javascript" src="../../static/js/bootstrap.js"></script>
</html>
